<html>
<#include "../common/header.ftl" />
<script type="text/javascript">
	$(function() {
		$('#edit').on('click', function() {
			if (($("#newPassword").val().trim()) == '') {
				tip('请输入新密码');
				return;
			}
			if (($("#password").val().trim()) == '') {
				tip('请输入新密码');
				return;
			}
			if (($("#rePassword").val().trim()) == '') {
				tip('请重复输入新密码！');
				return;
			}
			if ($("#rePassword").val().trim() != $("#newPassword").val().trim()) {
				tip('还爱着Ta?');
				return;
			}
			let obj = {};
			obj.uId = parseInt($("#uid").val().trim());
			obj.prePassword = $("#password").val();
			obj.newPassword = $("#newPassword").val();
			console.log(JSON.parse(JSON.stringify(obj)))
			$.ajax({
				url : "user?method=edit",
				type : "POST",
				data : JSON.stringify(obj),
				scriptCharset : 'utf-8',
				contentType : "application/json; charset=utf-8",
				success : function(res) {
					let data = JSON.parse(res)
					let item = data.data
					console.log('data=>',data)
					if(data.code === 0 ){
						tip(data.msg+"请重新登录")
						setTimeout("location.href='login?method=logout'",1000)
					}
					if(data.code === 1 ){
						tip("旧密码输入错误！")
					}
				},
				error : function(res) {
					console.log("error", res);
				}
			});
			/* console.log('data', $('form').serializeArray()) */
		})
	});
	function tip (msg){
		$("#warn").text(msg)
		$("#modal-282051").click()
	}
</script>

</head>

<#if Session.user ?? && Session.user.role==1>
<body style="margin-left: 200px">
 <a id="modal-282051" href="#modal-warns" style="display:none" role="button" class="" data-toggle="modal"></a>

	<div id="wrapper" class="toggled"><#include "../common/nav.ftl"
		/></div>
	<#else>
<body>
	</#if>

	<div class="container">
	<div class="modal fade" id="modal-warns" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
					<div class="modal-header">
							 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
							<h2 class="modal-title" id="myModalLabel">
								Tips!
							</h2>
						</div>
						<div  class="modal-body">
							<h3 id="warn" style="color:red">
						</div>
						<div class="modal-footer">
						<a id="modal-warn-login" style="display:none" data-toggle="modal" data-target="#login" class="btn " type="button"  data-dismiss="modal" href=""><span class="glyphicon glyphicon-log-in"></span> 去登录</a>
						<a id="modal-warn-ok" data-toggle="modal" class="btn " type="button"  data-dismiss="modal" href=""><span class="glyphicon glyphicon-ok"></span></a>
						</div>
					</div>
				</div>
			</div>
		<div class="row clearfix">
			<div class="col-md-12 column">
				<#include "../common/bread.ftl"/>
				<blockquote>
				<#if user ??>
				${user.nickname }
				<#if user.point gte 0 && user.point lt 200 > <img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_1.png" /></#if>
			<#if user.point gte 201 && user.point lt 300 > <img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_2.png" /></#if>
			<#if user.point gte 301 && user.point lt 400 > <img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_3.png" /></#if>
			<#if user.point gte 401> <img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_4.png" /></#if>
			</#if>
				</blockquote>
				<div id="box"
					class="alert alert-success alert-dismissable"
					<strong>
					<div class="progress">
			<#if user.point gte 0 && user.point lt 200 ><img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_2.png" /></#if>
			<#if user.point gte 200 && user.point lt 300 ><img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_3.png" /></#if>
			<#if user.point gte 300 && user.point lt 400 ><img
			style="width: 18px; padding-bottom:4px"
			src="static/image/v_4.png" /></#if>
			<#if user.point gte 401>  </#if>
					  <div class="progress-bar" role="progressbar" aria-valuenow="${user.point }" aria-valuemin="0" aria-valuemax="
			<#if user.point gte 0 && user.point lt 200 >200</#if>
			<#if user.point gte 200 && user.point lt 300 >300</#if>
			<#if user.point gte 300 && user.point lt 400 >400</#if>
			<#if user.point gte 401>${user.point } </#if>
					  " style="
			<#if user.point gte 0 && user.point lt 200 >width:${user.point/2 }%; </#if>
			<#if user.point gte 200 && user.point lt 300 >width:${(user.point-200) }%; </#if>
			<#if user.point gte 300 && user.point lt 400 >width:${(user.point-300) }% </#if>
			<#if user.point gte 400 >width:100% </#if>
					   ">
			<#if user.point gte 0 && user.point lt 200 >${(user.point/2)?string(0.00)} %</#if>
			<#if user.point gte 200 && user.point lt 300 >${(user.point-200)?string(0.00) } %</#if>
			<#if user.point gte 300 && user.point lt 400 >${(user.point-300)?string(0.00) } %</#if>
			<#if user.point gte 400  >100 %</#if>
					  </div>
					</div>
					</strong>
					<p class="text-error">
						<em>我的经验：</em>${user.point } /
						<#if user.point gte 0 && user.point lt 200 >200 </#if>
			<#if user.point gte 200 && user.point lt 300 >300 </#if>
			<#if user.point gte 300 && user.point lt 400 >400 </#if>
			<#if user.point gte 400  ><span style="color:#eea345">MAX</span> </#if>
					</p>
					<p>
						ID：<#if user.id ??>${ user.id }</#if>
					</p>
					
					<p>
						我的身份：<#if user.role ?? && user.role == 0 >普通会员<#else><span style="color:#eea345">超级管理员</span></#if>
					</p>
				</div>
				<#if key ?? && key=="edit">
				<div class="list-group">
					<div class="panel panel-primary">
						<div class="panel-body">
							<form role="form" action="" method="post">
					<div class="form-group">
						<label>旧密码：</label> <input id="password" type="password"
							class="form-control" name="prePassword" placeholder="旧爱" />
					</div>
					<div class="form-group">
						<label>新密码：</label> <input id="newPassword" type="password"
							class="form-control" name="newPassword" placeholder="新欢" />
					</div>
					<div class="form-group">
						<label>重复新密码：</label> <input id="rePassword" type="password"
							class="form-control" placeholder="重复" />
					</div>
					
					<input id="uid" type="hidden" value="${user.id }" />
					<button id="edit" type="button" class="btn btn-default">我意已决</button>
				</form>
						</div>
						<div class="panel-footer">
							<p class="list-group-item-text">修改密码</p>
						</div>
					</div>
				</div>
				</#if>
			</div> 
			</div>
		</div>
	</div>
		<script src="static/js/3.1.0bootstrap.min.js"></script>
</body>
</html>